//
//  KuKu_Version.m
//  kuku
//
//  Created by 清风徐来 on 2024/1/29.
//

#import "KuKu_Version.h"
#import <ZBNetworking/ZBNetworking.h>


@implementation KuKu_Version

/// 版本检测
+ (void)checkVersion {
    NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
    parameters[@"path"] = @"HomeViewController";
    parameters[@"id"]=@"66";
    parameters[@"p"]=@"1";
    [ZBRequestManager requestWithConfig:^(ZBURLRequest * _Nullable request) {
        request.path = @"";
        request.methodType =ZBMethodTypeGET;
        request.apiType = ZBRequestTypeRefresh;
        request.parameters = parameters;
    } success:^(id  _Nullable responseObject, ZBURLRequest * _Nullable request) {
        NSLog(@"请求成功：%@", responseObject);
    } failure:^(NSError * _Nullable error) {
        NSLog(@"请求失败：%@", error);
    }];
}

+ (void)downloadBinaryPatch {
    //  会默认创建下载路径/Library/Caches/ZBKit/AppDownload
    [ZBRequestManager requestWithConfig:^(ZBURLRequest * request) {
        request.url = @"http://dldir1.qq.com/qqfile/QQforMac/QQ_V4.2.4.dmg";
        request.methodType = ZBMethodTypeDownLoad;
        request.downloadState = ZBDownloadStateStart;
    } progress:^(NSProgress * _Nullable progress) {
        NSLog(@"onProgress: %.2f", 100.f * progress.completedUnitCount/progress.totalUnitCount);
    } success:^(id  responseObject,ZBURLRequest * request) {
        NSLog(@"ZBMethodTypeDownLoad 此时会返回存储路径文件: %@", responseObject);
        [self downLoadPathSize:[ZBRequestManager AppDownloadPath]];//返回下载路径的大小

        /*
         sleep(5);
         //清空下载的文件的路径
         [[ZBCacheManager sharedInstance]clearDiskWithPath:[ZBRequestManager AppDownloadPath] completion:^{
         NSLog(@"删除下载的文件");
         [self downLoadPathSize:[ZBRequestManager AppDownloadPath]];
         }];

         //删除下载的文件
         [[ZBCacheManager sharedInstance]clearCacheForkey:request.url inPath:[ZBRequestManager AppDownloadPath] completion:^{
         NSLog(@"删除下载的文件");
         }];
         */

    } failure:^(NSError * _Nullable error) {
        NSLog(@"error: %@", error);
    }];
}

+ (void)downLoadPathSize:(NSString *)path {
    CGFloat downLoadPathSize = [[ZBCacheManager sharedInstance]getFileSizeWithPath:path];
    downLoadPathSize = downLoadPathSize/1000.0/1000.0;
    NSLog(@"downLoadPathSize: %.2fM", downLoadPathSize);
}

@end
